package com.qing.cheng.service.impl;

import com.qing.cheng.constant.SysConstant;
import com.qing.cheng.dto.RegisterDto;
import com.qing.cheng.entity.QcStudent;
import com.qing.cheng.entity.QcUser;
import com.qing.cheng.mapper.QcStudentMapper;
import com.qing.cheng.mapper.QcUserMapper;
import com.qing.cheng.service.RegisterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class RegisterServiceImpl implements RegisterService {

    @Autowired(required = false)
    private QcUserMapper qcUserMapper;

    @Autowired(required = false)
    private QcStudentMapper qcStudentMapper;


    @Override
    public int register(RegisterDto registerDto) {
        Date date = new Date();
        QcUser qcUser = registerDto.getQcUser();
        qcUser.setCreatedBy(SysConstant.SYSTEM_NAME);
        qcUser.setUpdatedBy(SysConstant.SYSTEM_NAME);
        qcUser.setUpdatedDate(date);
        qcUser.setCreatedDate(date);
        qcUserMapper.insertSelective(qcUser);
        QcStudent qcStudent = registerDto.getQcStudent();
        qcStudent.setUserId(qcUser.getId());
        qcStudent.setCreatedBy(SysConstant.SYSTEM_NAME);
        qcStudent.setUpdatedBy(SysConstant.SYSTEM_NAME);
        qcStudent.setUpdatedDate(date);
        qcStudent.setCreatedDate(date);
        return qcStudentMapper.insertSelective(qcStudent);
    }
}
